package com.llkj.qingnianguoxue.adapter;

import android.widget.ImageView;
import android.widget.LinearLayout;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.llkj.qingnianguoxue.R;
import com.llkj.qingnianguoxue.bean.ZhiBoGiftBean;
import com.llkj.qingnianguoxue.util.DisplayUtil;
import com.llkj.qingnianguoxue.util.ImageLoadingUtil;

import java.util.List;

/**
 * 礼物适配器
 */
public class GiftAdapter extends BaseQuickAdapter<ZhiBoGiftBean, BaseViewHolder> {

    private int mCurrentPosition = -1;
    public GiftAdapter(int layoutResId, List<ZhiBoGiftBean> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(BaseViewHolder baseViewHolder, ZhiBoGiftBean item) {
        baseViewHolder.setText(R.id.tv_gift_name,item.getGiftName());
        ImageView ivGiftPic = baseViewHolder.getView(R.id.iv_gift_pic);
        ImageLoadingUtil.loadingUrl(ivGiftPic,item.getUrl());

        if(Float.parseFloat(item.getPrice())>0){
            baseViewHolder.setText(R.id.tv_gift_price, item.getPrice()+"银子");
        }else{
            baseViewHolder.setText(R.id.tv_gift_price,"免费");
        }

        LinearLayout llGift = baseViewHolder.getView(R.id.ll_root);
        LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) llGift.getLayoutParams();
        params.width = (DisplayUtil.getDensityWdith(mContext)-DisplayUtil.dip2px(mContext,50))/3;
        params.height = params.width/2+DisplayUtil.dip2px(mContext,50);
        LinearLayout.LayoutParams picParam = (LinearLayout.LayoutParams) ivGiftPic.getLayoutParams();
        picParam.height = params.width/2;

        if(mCurrentPosition == baseViewHolder.getLayoutPosition()){
            llGift.setSelected(true);
        }else{
            llGift.setSelected(false);
        }
    }

    public void setSelectGift(int position){
        mCurrentPosition = position;
        notifyDataSetChanged();
    }
}
